//
//  WBPictureView.swift
//  sinaWeibo
//
//  Created by 吴熠 on 16/11/16.
//  Copyright © 2016年 吴熠. All rights reserved.
//

import UIKit

private let cellID = "collection"
class WBPictureView: UICollectionView {

    //图片信息是以字典数组保存的
    var pictureInfo : [WBPictureInfo]?{
        didSet{
            //刷新数据
            self.reloadData()
        }
    }
    
    override func awakeFromNib() {
        let nib = UINib(nibName: "WBPictureCell", bundle: nil)
        self.register(nib, forCellWithReuseIdentifier: cellID)
        self.dataSource = self
    }
}

extension WBPictureView : UICollectionViewDataSource{
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return self.pictureInfo?.count ?? 0
    }
    
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellID, for: indexPath) as! WBPictureCell
        let pictureInfo = self.pictureInfo![indexPath.item]
        cell.pictureInfo = pictureInfo
        return cell
    }
    
    
}

